package com.cdvtc.fengchao.Servlet;

import com.cdvtc.fengchao.model.Product;
import com.cdvtc.fengchao.dao.ProductsDAO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet({"/", "/products"}) // 关键修改：添加根路径"/"
public class ProductServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 加载数据
        List<Product> products = new ProductsDAO().getAllProducts();
        request.setAttribute("products", products);

        // 转发到首页（index.jsp）
        request.getRequestDispatcher("/index.jsp").forward(request, response);
    }
}